package kr.saeildamil.androidstudy.ch11;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class RadioCheckEx extends Activity {
	TextView tv;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_radiocheck);

		tv = (TextView) findViewById(R.id.ch11_radiocheck_tv);

		RadioGroup radioGroup = (RadioGroup) findViewById(R.id.colorgroup);
		CheckBox checkBox = (CheckBox) findViewById(R.id.ch11_chkwhiteback);
		ToggleButton toggleButton = (ToggleButton) findViewById(R.id.ch11_tglanguage);

		radioGroup.setOnCheckedChangeListener(mlistener);
		checkBox.setOnCheckedChangeListener(listener);
		toggleButton.setOnCheckedChangeListener(listener);

	}

	RadioGroup.OnCheckedChangeListener mlistener = new RadioGroup.OnCheckedChangeListener() {
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			if (group.getId() == R.id.colorgroup) {
				switch (checkedId) {
				case R.id.ch11_rared:
					tv.setTextColor(Color.RED);
					break;
				case R.id.ch11_ragreen:
					tv.setTextColor(Color.GREEN);
					break;
				case R.id.ch11_rablue:
					tv.setTextColor(Color.BLUE);
					break;
				}
			}

		}

	};

	CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton btnView, boolean isChecked) {
			if (btnView.getId() == R.id.ch11_chkwhiteback) {
				if (isChecked) {
					tv.setBackgroundColor(Color.WHITE);
				} else {
					tv.setBackgroundColor(Color.TRANSPARENT);
				}
			}
			if (btnView.getId() == R.id.ch11_tglanguage) {
				if(isChecked){
					tv.setText("샘플");
				} else {
					tv.setText("Sample");
				}
			}
		}

	};

}
